{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "1affd6d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pymilvus import MilvusClient, DataType\n",
    "\n",
    "uri = \"https://in03-338d6950a393b2c.serverless.gcp-us-west1.cloud.zilliz.com\"\n",
    "token = \"xxxxx\"\n",
    "\n",
    "\n",
    "client = MilvusClient(\n",
    "    uri=uri,\n",
    "    token=token\n",
    ")\n",
    "\n",
    "# Create schema\n",
    "schema = MilvusClient.create_schema(auto_id=False)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "0f2c396c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'auto_id': False, 'description': '', 'fields': [{'name': 'pk', 'description': '主键', 'type': <DataType.VARCHAR: 21>, 'params': {'max_length': 100}, 'is_primary': True, 'auto_id': False}, {'name': 'image_embedding', 'description': '图片向量', 'type': <DataType.FLOAT_VECTOR: 101>, 'params': {'dim': 256}}, {'name': 'text_embedding', 'description': '文本向量', 'type': <DataType.FLOAT_VECTOR: 101>, 'params': {'dim': 256}}, {'name': 'gender', 'description': '性别', 'type': <DataType.VARCHAR: 21>, 'params': {'max_length': 200}}, {'name': 'product_type', 'description': '产品类型', 'type': <DataType.VARCHAR: 21>, 'params': {'max_length': 200}}, {'name': 'caption', 'description': '图片描述', 'type': <DataType.VARCHAR: 21>, 'params': {'max_length': 2000, 'enable_match': True, 'enable_analyzer': True, 'analyzer_params': '{\"type\":\"english\"}'}}], 'enable_dynamic_field': False}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Add primary key field\n",
    "schema.add_field(\n",
    "    field_name=\"pk\",\n",
    "    datatype=DataType.VARCHAR,\n",
    "    is_primary=True,\n",
    "    max_length=100,\n",
    "    description=\"主键\"\n",
    ")\n",
    "\n",
    "# Add image vector field\n",
    "schema.add_field(\n",
    "    field_name=\"image_embedding\",\n",
    "    datatype=DataType.FLOAT_VECTOR,\n",
    "    dim=256,\n",
    "    description=\"图片向量\"\n",
    ")\n",
    "\n",
    "# Add text vector field\n",
    "schema.add_field(\n",
    "    field_name=\"text_embedding\",\n",
    "    datatype=DataType.FLOAT_VECTOR,\n",
    "    dim=256,\n",
    "    description=\"文本向量\"\n",
    ")\n",
    "\n",
    "# Add gender field\n",
    "schema.add_field(\n",
    "    field_name=\"gender\",\n",
    "    datatype=DataType.VARCHAR,\n",
    "    max_length=200,\n",
    "    description=\"性别\"\n",
    ")\n",
    "\n",
    "# Add product type field\n",
    "schema.add_field(\n",
    "    field_name=\"product_type\",\n",
    "    datatype=DataType.VARCHAR,\n",
    "    max_length=200,\n",
    "    description=\"产品类型\"\n",
    ")\n",
    "\n",
    "# Add caption field\n",
    "analyzer_params = {\n",
    "    \"type\": \"english\"\n",
    "}\n",
    "schema.add_field(\n",
    "    field_name=\"caption\",\n",
    "    datatype=DataType.VARCHAR,\n",
    "    max_length=2000,\n",
    "    enable_analyzer=True,\n",
    "    analyzer_params=analyzer_params,\n",
    "    enable_match=True,\n",
    "    description=\"图片描述\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "71115942",
   "metadata": {},
   "outputs": [],
   "source": [
    "index_params = client.prepare_index_params()\n",
    "\n",
    "index_params.add_index(\n",
    "    field_name=\"pk\"\n",
    ")\n",
    "\n",
    "index_params.add_index(\n",
    "    field_name=\"image_embedding\", \n",
    "    index_type=\"AUTOINDEX\",\n",
    "    metric_type=\"IP\"\n",
    ")\n",
    "\n",
    "index_params.add_index(\n",
    "    field_name=\"text_embedding\", \n",
    "    index_type=\"AUTOINDEX\",\n",
    "    metric_type=\"IP\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "856d6df5",
   "metadata": {},
   "outputs": [],
   "source": [
    "client.create_collection(\n",
    "    collection_name=\"fasion_multimodel_embedding\",\n",
    "    schema=schema,\n",
    "    index_params=index_params\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfbb87d3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "multimodel",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
